<template>
  <div class="search">
    <van-nav-bar left-text="搜索" left-arrow @click-left="onClickLeft" />
    <van-search
      v-model="text"
      shape="round"
      placeholder="请输入搜索关键词"
      @search="onSearch"
      @cancel="onCancel"
    />
    <router-view></router-view>
  </div>
</template>

<script>
import { Toast } from "vant";
import { shop_search } from "../api";
export default {
  data() {
    return {
      text: "",
      list:[]
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push("/footer/host");
    },
    onSearch() {
      if (this.text) {
        this.$store.commit("addSear", this.text);
        this.text = "";
        shop_search({ searchkey: this.text }).then((res) => {
          if (res.data.code == 200) {
            // console.log(res.data.list);
            this.$router.push('/search/all')
            this.list = res.data.list
            this.$store.commit("addList",this.list)
            // console.log(this.list);
          }
        });
      } else {
        Toast("输入不能为空");
      }
    },
    onCancel() {
      Toast("取消");
    },
  },
  mounted() {},
};
</script>

<style scoped>
.search {
  width: 100%;
  height: 100%;
}

</style>